

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="运行环境  windows11 JDK 8 anaconda3 python 3.9 Neo4j 3.5.32 python jupyter库 py2neo Visual Studio Code 2022  项目地址：Gitee : https:&#x2F;&#x2F;gitee.com&#x2F;ccuni&#x2F;py2neo-neo4j-actual-combat GitHub:https:&#x2F;&#x2F;github.com&#x2F;unirit">
<meta property="og:type" content="article">
<meta property="og:title" content="Neo4j 项目实战_基于Py2Neo构建电影知识图谱">
<meta property="og:url" content="http://example.com/2022/05/19/Neo4j%20%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98_%E5%9F%BA%E4%BA%8EPy2Neo%E6%9E%84%E5%BB%BA%E7%94%B5%E5%BD%B1%E7%9F%A5%E8%AF%86%E5%9B%BE%E8%B0%B1/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="运行环境  windows11 JDK 8 anaconda3 python 3.9 Neo4j 3.5.32 python jupyter库 py2neo Visual Studio Code 2022  项目地址：Gitee : https:&#x2F;&#x2F;gitee.com&#x2F;ccuni&#x2F;py2neo-neo4j-actual-combat GitHub:https:&#x2F;&#x2F;github.com&#x2F;unirit">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/d099d6e8bc1f4ae88be213222e719d4d.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/1a861b0ce7b548cab1e082cabeca158f.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/5f4039f3d9aa4129b048bf5611c6fb77.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/9099a5d68638448d84fe68e21877d1fd.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/4e7f380f5e4d41df913d640fd05ea7be.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/4b664662ca7e4da0ab07652f0eda2d88.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/7b964f472bdc417488ccc22bb1a798e0.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/b88ae3aa1d8645a3b9d6de154a8047cb.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/a9fe7407560442808e6a76d6af4ecb69.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/e37ec16a6d874fd5885bbce0ee9cfb2c.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/9a6b25c6bae44844bf9ed0666cf97b42.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/319133bc9f9245ba913a465e867dce0a.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/472dab5e7e67422cb92aee0d7563ffca.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/c5f25294810341b69a91d78f5a1bc424.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2fb3908717e44433bcf09117689c7e11.png">
<meta property="article:published_time" content="2022-05-19T11:47:54.000Z">
<meta property="article:modified_time" content="2022-08-22T15:47:10.661Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="项目实战">
<meta property="article:tag" content="Neo4j">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/d099d6e8bc1f4ae88be213222e719d4d.png">
  
  
  
  <title>Neo4j 项目实战_基于Py2Neo构建电影知识图谱 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Neo4j 项目实战_基于Py2Neo构建电影知识图谱"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-05-19 19:47" pubdate>
          2022年5月19日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          6.3k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          53 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Neo4j 项目实战_基于Py2Neo构建电影知识图谱</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>windows11</li>
<li>JDK 8</li>
<li>anaconda3</li>
<li>python 3.9</li>
<li>Neo4j 3.5.32</li>
<li>python jupyter库</li>
<li>py2neo</li>
<li>Visual Studio Code 2022</li>
</ul>
<p>项目地址：<br><strong>Gitee :</strong> <a target="_blank" rel="noopener" href="https://gitee.com/ccuni/py2neo-neo4j-actual-combat">https://gitee.com/ccuni/py2neo-neo4j-actual-combat</a></p>
<p><strong>GitHub:</strong><a target="_blank" rel="noopener" href="https://github.com/unirithe/py2neo-neo4j-actual-combat">https://github.com/unirithe/py2neo-neo4j-actual-combat</a></p>
<h1 id="一、数据集说明"><a href="#一、数据集说明" class="headerlink" title="一、数据集说明"></a>一、数据集说明</h1><p>数据集来自 IMDB 影视网的电影、演员数据，数据并不全，仅供学习参考。<br>数据集参考上方的 Gitee 或 GitHub地址</p>
<ul>
<li><p>movie_act.csv        演员id到电影id的映射信息</p>
</li>
<li><p><img src="https://img-blog.csdnimg.cn/d099d6e8bc1f4ae88be213222e719d4d.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
</li>
<li><p>movie_actor.csv      5334个演员的信息，名称和头像<br><img src="https://img-blog.csdnimg.cn/1a861b0ce7b548cab1e082cabeca158f.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
</li>
<li><p>movie_moive.csv      2926部电影的详情信息<br><img src="https://img-blog.csdnimg.cn/5f4039f3d9aa4129b048bf5611c6fb77.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
</li>
<li><p>movie_popularity.csv 保留着62部受欢迎的电影信息<br><img src="https://img-blog.csdnimg.cn/9099a5d68638448d84fe68e21877d1fd.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
</li>
<li><p>user_user.csv  不知道有啥用的id信息<br><img src="https://img-blog.csdnimg.cn/4e7f380f5e4d41df913d640fd05ea7be.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
</li>
</ul>
<h1 id="二、数据预处理"><a href="#二、数据预处理" class="headerlink" title="二、数据预处理"></a>二、数据预处理</h1><p>这里将原先的csv数据转为 pandas的DataFrame后再转化成字典，从而能构建Node对象，插入到Neo4j中</p>
<h2 id="2-1-选择受欢迎的电影"><a href="#2-1-选择受欢迎的电影" class="headerlink" title="2.1 选择受欢迎的电影"></a>2.1 选择受欢迎的电影</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs python">list_mid = df[<span class="hljs-string">&#x27;popularity&#x27;</span>][<span class="hljs-string">&#x27;movieid_id&#x27;</span>]<br><br><span class="hljs-comment"># 查找受欢迎的电影信息</span><br><span class="hljs-comment"># Find the movies which is popularity </span><br>df_popularity_movie = df[<span class="hljs-string">&#x27;movie&#x27;</span>][df[<span class="hljs-string">&#x27;movie&#x27;</span>][<span class="hljs-string">&#x27;movieid&#x27;</span>].isin(list_mid)]<br>df_popularity_movie<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/4b664662ca7e4da0ab07652f0eda2d88.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 将DataFrame格式转化为dict，到时候方便插入Neo4j</span><br><span class="hljs-comment"># make DataFrame to Dict, in order to insert neo4j</span><br>dict_movie = &#123;&#125;<br><br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(df_popularity_movie)):<br>    row = df_popularity_movie.iloc[i]<br>    dict_movie.update(&#123;row[<span class="hljs-string">&#x27;movieid&#x27;</span>] : row.to_dict()&#125;)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;rows: &#x27;</span> , <span class="hljs-built_in">len</span>(dict_movie))<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/7b964f472bdc417488ccc22bb1a798e0.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-2-查找每部受欢迎电影的所有演员"><a href="#2-2-查找每部受欢迎电影的所有演员" class="headerlink" title="2.2 查找每部受欢迎电影的所有演员"></a>2.2 查找每部受欢迎电影的所有演员</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs python">dict_actor_movie = &#123;&#125;<br><span class="hljs-keyword">for</span> mid <span class="hljs-keyword">in</span> df_popularity_movie[<span class="hljs-string">&#x27;movieid&#x27;</span>]:<br>    flag = df[<span class="hljs-string">&#x27;actor_movie&#x27;</span>][<span class="hljs-string">&#x27;movieid_id&#x27;</span>].eq(mid)<br>    actors = df[<span class="hljs-string">&#x27;actor_movie&#x27;</span>][flag][<span class="hljs-string">&#x27;actorid_id&#x27;</span>].to_list()<br>    dict_actor_movie.update(&#123;mid : actors&#125;)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;rows: &#x27;</span> , <span class="hljs-built_in">len</span>(dict_actor_movie))<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/b88ae3aa1d8645a3b9d6de154a8047cb.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-3-查找热门电影里每个演员的信息"><a href="#2-3-查找热门电影里每个演员的信息" class="headerlink" title="2.3 查找热门电影里每个演员的信息"></a>2.3 查找热门电影里每个演员的信息</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs python">dict_actor = &#123;&#125;<br>actors = <span class="hljs-built_in">set</span>()<br><span class="hljs-keyword">for</span> ac <span class="hljs-keyword">in</span> dict_actor_movie.values():<br>    <span class="hljs-keyword">for</span> actor <span class="hljs-keyword">in</span> ac:<br>        actors.add(actor)<br><span class="hljs-keyword">for</span> aid <span class="hljs-keyword">in</span> actors:<br>    flag = (df[<span class="hljs-string">&#x27;actor&#x27;</span>][<span class="hljs-string">&#x27;actorid&#x27;</span>] == aid)<br>    row = df[<span class="hljs-string">&#x27;actor&#x27;</span>][flag].iloc[<span class="hljs-number">0</span>]<br>    dict_actor.update(&#123;aid: row.to_dict()&#125;)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;rows: &#x27;</span> , <span class="hljs-built_in">len</span>(dict_actor_movie))<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/a9fe7407560442808e6a76d6af4ecb69.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h1 id="三、Py2Neo-操作"><a href="#三、Py2Neo-操作" class="headerlink" title="三、Py2Neo 操作"></a>三、Py2Neo 操作</h1><h2 id="3-1-连接-Neo4j"><a href="#3-1-连接-Neo4j" class="headerlink" title="3.1 连接 Neo4j"></a>3.1 连接 Neo4j</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> py2neo <span class="hljs-keyword">import</span> Graph<br>url = <span class="hljs-string">&quot;http://localhost:7474&quot;</span><br>username = <span class="hljs-string">&quot;neo4j&quot;</span><br>password = <span class="hljs-string">&quot;123456&quot;</span><br>graph = Graph(url, auth=(username, password))<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;neo4j info: &#123;&#125;&quot;</span>.<span class="hljs-built_in">format</span>(<span class="hljs-built_in">str</span>(graph)))<br></code></pre></td></tr></table></figure>
<p>输出结果：neo4j info: Graph(‘<a href="http://localhost:7474&#39;">http://localhost:7474&#39;</a>)</p>
<h2 id="3-2-插入电影和演员节点"><a href="#3-2-插入电影和演员节点" class="headerlink" title="3.2 插入电影和演员节点"></a>3.2 插入电影和演员节点</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> py2neo <span class="hljs-keyword">import</span> Graph, Node, Subgraph<br><span class="hljs-keyword">import</span> time <br>s_time = time.time()<br><br>node_list = []<br><br>graph.delete_all()<br><br><span class="hljs-keyword">for</span> mid, movie <span class="hljs-keyword">in</span> dict_movie.items():<br>    node_list.append(Node(<span class="hljs-string">&quot;movie&quot;</span>, **movie))<br><span class="hljs-keyword">for</span> aid, actor <span class="hljs-keyword">in</span> dict_actor.items():<br>    node_list.append(Node(<span class="hljs-string">&quot;actor&quot;</span>, **actor))<br>graph.create(subgraph=Subgraph(node_list))<br><br><span class="hljs-comment"># 查看一个节点</span><br><span class="hljs-built_in">print</span>(node_list[<span class="hljs-number">0</span>])<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/e37ec16a6d874fd5885bbce0ee9cfb2c.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>输出当前Neo4j 电影和演员节点的个数</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;movie: &#x27;</span>, graph.nodes.<span class="hljs-keyword">match</span>(<span class="hljs-string">&quot;movie&quot;</span>).count())<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;actor: &#x27;</span>, graph.nodes.<span class="hljs-keyword">match</span>(<span class="hljs-string">&#x27;actor&#x27;</span>).count())<br></code></pre></td></tr></table></figure>
<p>输出结果：<br>movie:  62<br>actor:  240</p>
<h2 id="3-3-建立电影和演员之间的联系"><a href="#3-3-建立电影和演员之间的联系" class="headerlink" title="3.3 建立电影和演员之间的联系"></a>3.3 建立电影和演员之间的联系</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> py2neo <span class="hljs-keyword">import</span> NodeMatcher, Relationship<br>node_matcher = NodeMatcher(graph)<br>list_rel = []<br><span class="hljs-keyword">for</span> mid, actors <span class="hljs-keyword">in</span> dict_actor_movie.items(): <br>    node_movie = node_matcher.<span class="hljs-keyword">match</span>(<span class="hljs-string">&quot;movie&quot;</span>, movieid=mid).first()<br>    <span class="hljs-keyword">if</span> node_movie != <span class="hljs-literal">None</span>:<br>        <span class="hljs-keyword">for</span> actor <span class="hljs-keyword">in</span> actors:<br>            node_actor = node_matcher.<span class="hljs-keyword">match</span>(<span class="hljs-string">&quot;actor&quot;</span>, actorid=actor).first()<br>            <span class="hljs-keyword">if</span> node_actor != <span class="hljs-literal">None</span>:<br>                list_rel.append(Relationship(node_actor, <span class="hljs-string">&quot;acted&quot;</span>, node_movie, name=<span class="hljs-string">&#x27;acted&#x27;</span>))<br><br><span class="hljs-comment"># 批量建立</span><br><span class="hljs-comment"># batch build </span><br>once = <span class="hljs-number">50</span><br>maxi = <span class="hljs-built_in">len</span>(list_rel)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, maxi, once):<br>    subgraph = Subgraph(relationships=list_rel[i:i+once])<br>    graph.separate(subgraph)<br>    graph.create(subgraph)<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&#x27;[INFO] &gt;&gt; created <span class="hljs-subst">&#123;<span class="hljs-built_in">len</span>(subgraph)&#125;</span> relations&#x27;</span>)<br></code></pre></td></tr></table></figure>
<p>输出结果：<br><img src="https://img-blog.csdnimg.cn/9a6b25c6bae44844bf9ed0666cf97b42.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>登录 Neo4j 的web页面查询插入的结果：<a target="_blank" rel="noopener" href="http://localhost:7474/">http://localhost:7474</a></p>
<p>![&#96;](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/6891ff5b6556490f8edbc482be550c04.png">https://img-blog.csdnimg.cn/6891ff5b6556490f8edbc482be550c04.png</a>)</p>
<h1 id="四、基于Neo4j的数据分析"><a href="#四、基于Neo4j的数据分析" class="headerlink" title="四、基于Neo4j的数据分析"></a>四、基于Neo4j的数据分析</h1><h2 id="4-1-查找电影的所有关系"><a href="#4-1-查找电影的所有关系" class="headerlink" title="4.1 查找电影的所有关系"></a>4.1 查找电影的所有关系</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> py2neo <span class="hljs-keyword">import</span> RelationshipMatcher<br>rmatcher = RelationshipMatcher(graph)<br><br>i = <span class="hljs-number">0</span><br><span class="hljs-keyword">for</span> node_movie <span class="hljs-keyword">in</span> graph.nodes.<span class="hljs-keyword">match</span>(<span class="hljs-string">&#x27;movie&#x27;</span>).<span class="hljs-built_in">all</span>():<br>    <span class="hljs-built_in">print</span>(i, <span class="hljs-string">&#x27;-&#x27;</span> * <span class="hljs-number">10</span> , node_movie[<span class="hljs-string">&#x27;name&#x27;</span>] + <span class="hljs-string">&#x27;-&#x27;</span> *<span class="hljs-number">10</span>)<br>    <span class="hljs-keyword">for</span> rel <span class="hljs-keyword">in</span> graph.<span class="hljs-keyword">match</span>([<span class="hljs-literal">None</span>, node_movie]).<span class="hljs-built_in">all</span>():<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;--&#x27;</span>, rel)<br>    i += <span class="hljs-number">1</span><br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;\n\n&#x27;</span>)<br></code></pre></td></tr></table></figure>
<p>部分输出结果：（共有62部受欢迎的电影）<br><img src="https://img-blog.csdnimg.cn/319133bc9f9245ba913a465e867dce0a.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="4-2-查找根据演员数和评分排序的Top10电影"><a href="#4-2-查找根据演员数和评分排序的Top10电影" class="headerlink" title="4.2 查找根据演员数和评分排序的Top10电影"></a>4.2 查找根据演员数和评分排序的Top10电影</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs python">nodes_movie = graph.nodes.<span class="hljs-keyword">match</span>(<span class="hljs-string">&#x27;movie&#x27;</span>).<span class="hljs-built_in">all</span>()<br><br><span class="hljs-comment">#关于已出现的演员人数的前十名</span><br><span class="hljs-comment"># Top10 about the number of appeared actor  </span><br><br><span class="hljs-comment"># 如果演员人数一致就根据评分判断，选择评分高的电影</span><br><span class="hljs-comment"># If the number of actors is the same,</span><br><span class="hljs-comment">#   judge according to the score and choose the film with high rate.</span><br>rm = RelationshipMatcher(graph)<br><span class="hljs-string">&#x27;&#x27;&#x27;</span><br><span class="hljs-string">    Top10</span><br><span class="hljs-string">&#x27;&#x27;&#x27;</span><br>dict_movie_top10 = &#123;&#125;<br><span class="hljs-keyword">for</span> node_movie <span class="hljs-keyword">in</span> nodes_movie:<br>    list_actors = rm.<span class="hljs-keyword">match</span>([<span class="hljs-literal">None</span>, node_movie], r_type=<span class="hljs-string">&#x27;acted&#x27;</span>).<span class="hljs-built_in">all</span>()<br>    count = <span class="hljs-built_in">len</span>(list_actors)<br>    dict_movie_top10.update(&#123;node_movie: &#123;<span class="hljs-string">&#x27;count&#x27;</span>:<span class="hljs-built_in">int</span>(count), <span class="hljs-string">&#x27;actors&#x27;</span>:list_actors&#125;&#125;)<br><br>list_movie_top10 = <span class="hljs-built_in">sorted</span>(dict_movie_top10.items(), <br>        key = <span class="hljs-keyword">lambda</span> k : (k[<span class="hljs-number">1</span>][<span class="hljs-string">&#x27;count&#x27;</span>], <span class="hljs-built_in">float</span>(k[<span class="hljs-number">0</span>][<span class="hljs-string">&#x27;rate&#x27;</span>])), reverse=<span class="hljs-literal">True</span>)[:<span class="hljs-number">10</span>]<br><br><span class="hljs-comment"># list_movie_top10 is a list([turple(Node, dict)])</span><br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;------------------ Top10 ------------------&#x27;</span>)<br><span class="hljs-keyword">for</span> node_movie, dict_count <span class="hljs-keyword">in</span> list_movie_top10:<br>    <span class="hljs-built_in">print</span>(dict_count[<span class="hljs-string">&#x27;count&#x27;</span>], node_movie[<span class="hljs-string">&#x27;rate&#x27;</span>], node_movie[<span class="hljs-string">&#x27;name&#x27;</span>])<br></code></pre></td></tr></table></figure>
<p>输出结果：<br><img src="https://img-blog.csdnimg.cn/472dab5e7e67422cb92aee0d7563ffca.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>翻译过后：<br><code>Translate to chinese</code></p>
<table>
<thead>
<tr>
<th>排名</th>
<th>评分</th>
<th>电影名称</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>9.1</td>
<td>《肖申克的救赎》</td>
</tr>
<tr>
<td>2</td>
<td>9.1</td>
<td>《Dekalog》</td>
</tr>
<tr>
<td>3</td>
<td>9.0</td>
<td>《黑暗骑士》</td>
</tr>
<tr>
<td>4</td>
<td>9.0</td>
<td>《教父:第二部》</td>
</tr>
<tr>
<td>5</td>
<td>8.9</td>
<td>《低俗小说》</td>
</tr>
<tr>
<td>6</td>
<td>8.8</td>
<td>《费城总是阳光明媚》</td>
</tr>
<tr>
<td>7</td>
<td>8.8</td>
<td>《星球大战5:帝国反击战》</td>
</tr>
<tr>
<td>8</td>
<td>8.8</td>
<td>《搏击俱乐部》</td>
</tr>
<tr>
<td>9</td>
<td>8.7</td>
<td>《指环王:双塔奇兵》</td>
</tr>
<tr>
<td>10</td>
<td>8.6</td>
<td>《星球大战》</td>
</tr>
</tbody></table>
<h2 id="4-3-保存-Top10数据到-Neo4j"><a href="#4-3-保存-Top10数据到-Neo4j" class="headerlink" title="4.3 保存 Top10数据到 Neo4j"></a>4.3 保存 Top10数据到 Neo4j</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs python">graph.delete(Subgraph(graph.nodes.<span class="hljs-keyword">match</span>(<span class="hljs-string">&#x27;actor_top10&#x27;</span>).<span class="hljs-built_in">all</span>()))<br>graph.delete(Subgraph(graph.nodes.<span class="hljs-keyword">match</span>(<span class="hljs-string">&#x27;movie_top10&#x27;</span>).<span class="hljs-built_in">all</span>()))<br>graph.delete(Subgraph(RelationshipMatcher(graph).<span class="hljs-keyword">match</span>(name=<span class="hljs-string">&#x27;acted_top10&#x27;</span>)))<br><br>rel_top10 = []<br>nodeMatcher = NodeMatcher(graph)<br><span class="hljs-keyword">for</span> node_movie, dict_count <span class="hljs-keyword">in</span> list_movie_top10:<br>    <span class="hljs-keyword">for</span> actor_rel <span class="hljs-keyword">in</span> dict_count[<span class="hljs-string">&#x27;actors&#x27;</span>]:<br><br>        actor = Node(<span class="hljs-string">&#x27;actor_top10&#x27;</span>, **<span class="hljs-built_in">dict</span>(actor_rel.start_node))<br>        movie = Node(<span class="hljs-string">&#x27;movie_top10&#x27;</span>, **<span class="hljs-built_in">dict</span>(node_movie))<br><br>        actor_find = nodeMatcher.<span class="hljs-keyword">match</span>(<span class="hljs-string">&#x27;actor_top10&#x27;</span>, name=actor[<span class="hljs-string">&#x27;name&#x27;</span>]).first()<br>        movie_find = nodeMatcher.<span class="hljs-keyword">match</span>(<span class="hljs-string">&#x27;movie_top10&#x27;</span>, name=movie[<span class="hljs-string">&#x27;name&#x27;</span>]).first()<br>        <span class="hljs-keyword">if</span> actor_find != <span class="hljs-literal">None</span>: ator = actor_find <br>        <span class="hljs-keyword">if</span> movie_find != <span class="hljs-literal">None</span>: movie = movie_find<br>        <br>        rel_top10.append(Relationship(actor, <span class="hljs-string">&quot;acted&quot;</span>, movie, name=<span class="hljs-string">&#x27;acted_top10&#x27;</span>))<br>        sub_rels=Subgraph(relationships=rel_top10)<br>        graph.separate(subgraph=sub_rels)<br>        graph.create(subgraph = sub_rels)<br><br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;The number of actor_top10 node: &#x27;</span>,graph.nodes.<span class="hljs-keyword">match</span>(<span class="hljs-string">&#x27;actor_top10&#x27;</span>).count())<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;The number of moive_top10 node: &#x27;</span>, graph.nodes.<span class="hljs-keyword">match</span>(<span class="hljs-string">&#x27;movie_top10&#x27;</span>).count())<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;The number of relationsip: &#x27;</span>, graph.relationships.<span class="hljs-keyword">match</span>(name=<span class="hljs-string">&#x27;acted_top10&#x27;</span>).count())<br></code></pre></td></tr></table></figure>
<p>输出结果：<br><img src="https://img-blog.csdnimg.cn/c5f25294810341b69a91d78f5a1bc424.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>从 web中查询的结果如下：<br><img src="https://img-blog.csdnimg.cn/2fb3908717e44433bcf09117689c7e11.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h1 id="五、总结"><a href="#五、总结" class="headerlink" title="五、总结"></a>五、总结</h1><p>通过本次的尝试，我们使用py2neo进行了Neo4j的增删改查，熟悉使用 Node、Relationship、Graph，另外，还有大量的 pandas相关的操作。最终分析了影视电影和演员之间的关系，当然还有更多指标可以分析，比如：出现次数最多的演员以及电影、同步出现率最高的电影等等。</p>
<p>py2neo实现neo4j的增删改查还是挺轻松的。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/" class="category-chain-item">数据库</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/">#项目实战</a>
      
        <a href="/tags/Neo4j/">#Neo4j</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Neo4j 项目实战_基于Py2Neo构建电影知识图谱</div>
      <div>http://example.com/2022/05/19/Neo4j 项目实战_基于Py2Neo构建电影知识图谱/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年5月19日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/05/20/%E8%AF%BE%E8%AE%BE%E6%80%BB%E7%BB%93%20_%20%E5%88%9D%E5%AD%A6%E8%80%85SpringBoot%E6%A1%86%E6%9E%B6%E5%BC%80%E5%8F%91%E5%AD%98%E5%9C%A8%E7%9A%84%E9%97%AE%E9%A2%98%E6%80%BB%E7%BB%93%20_%20%E5%95%86%E5%9F%8E%E7%B3%BB%E7%BB%9F%E7%9A%84%E8%AE%BE%E8%AE%A1%E9%97%AE%E9%A2%98%E6%80%BB%E7%BB%93/" title="课设总结 _ 初学者SpringBoot框架开发存在的问题总结 _ 商城系统的设计问题总结">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">课设总结 _ 初学者SpringBoot框架开发存在的问题总结 _ 商城系统的设计问题总结</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/05/06/MongoDB%20%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20%E5%9F%BA%E4%BA%8EPyMongo%E7%9A%84%E7%94%B5%E5%BD%B1%E5%BD%B1%E8%AF%84%E5%88%86%E6%9E%90%20_%20%E5%AF%B9%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%9C%E8%BF%9B%E8%A1%8C%E5%8F%AF%E8%A7%86%E5%8C%96%E5%B1%95%E7%A4%BA%E4%BB%A5%E5%8F%8A%E5%88%86%E6%9E%90%20_%20%E8%AF%84%E8%AE%BA%E8%AF%8D%E4%BA%91%20_%20%E5%88%86%E6%97%B6%E9%97%B4%E6%AE%B5%E5%88%86%E6%9E%90/" title="MongoDB 项目实战 基于PyMongo的电影影评分析 _ 对数据结果进行可视化展示以及分析 _ 评论词云 _ 分时间段分析">
                        <span class="hidden-mobile">MongoDB 项目实战 基于PyMongo的电影影评分析 _ 对数据结果进行可视化展示以及分析 _ 评论词云 _ 分时间段分析</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
